import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2024-02-22
 * Time:10:27
 */
public class Solution {
    //和为 k 的子数组
    public static int subarraySum(int[] nums, int k) {
        int count = 0;
        HashMap<Integer,Integer> map = new HashMap<>();

        int sum = 0;
        for(int i = 0;i < nums.length;i++) {
            sum += nums[i];
            if(sum == k) count++;  //处理 [0,i] 刚好和为 k 的情况（包括整个数组和为 k 的情况）
            count += map.getOrDefault(sum-k,0);
            map.put(sum,map.getOrDefault(sum,0) + 1);
        }
        return count;
    }
    /////////////////////////////////////
    //提莫攻击
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int ans = 0;
        for(int i = 0;i < timeSeries.length-1;i++) {
            if(timeSeries[i] + duration <= timeSeries[i+1]) ans += duration;
            else ans += timeSeries[i+1] - timeSeries[i];
        }

        ans += duration;
        return ans;
    }


}
